package com.zhaoyan.okgorxjavademo.base;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;


import com.zhaoyan.okgorxjavademo.R;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * Created by cxy on 2017/5/23.
 */

public abstract class Simple1Activity extends SwipeBackActivity {
    protected Activity mContext;
    private Unbinder unbinder;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 21){
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        setContentView(getLayout());
        sp = getSharedPreferences("config", MODE_PRIVATE);
        editor = sp.edit();
        unbinder = ButterKnife.bind(this);
        mContext = this;
        initEventAndData();
        onViewCreated();
    }

    protected void onViewCreated() {

    }

    protected abstract int getLayout();

    protected abstract void initEventAndData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, R.anim.activity_right_out);
    }

    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
        overridePendingTransition(R.anim.activity_left_in, R.anim.activity_right_out);
    }

    public void onResume() {
        super.onResume();
    }

    public void onPause() {
        super.onPause();
    }

    public void putString(String value, String key) {
        editor.putString(value, key);
        editor.commit();
    }

    public void putInt(String value, int key) {
        editor.putInt(value, key);
        editor.commit();
    }
    public void putBoolean(String key,boolean value) {
        editor.putBoolean(key,value);
        editor.commit();
    }

    public String getString(String value) {
        return sp.getString(value, "");
    }

    public int getInt(String value) {
        return sp.getInt(value, 0);
    }
    public boolean getBoolean(String key) {
        return sp.getBoolean(key,false);
    }
}
